<?php

use yii\db\Migration;

/**
 * Class m171206_062801_createTableContent
 */
class m171206_062801_createTableContent extends Migration
{
    /**
     * @inheritdoc
     */
    public function safeUp()
    {
        $tableOptions = null;
        if ($this->db->driverName === 'mysql') {
            // http://stackoverflow.com/questions/766809/whats-the-difference-between-utf8-general-ci-and-utf8-unicode-ci
            $tableOptions = 'CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci ENGINE=InnoDB';
        }

        $this->createTable('{{%course_content}}', [

            'id' => $this->string(50)->notNull()->defaultValue('')->comment('目录ID'),
            'user_id' => $this->integer()->notNull()->defaultValue(0)->comment('用户ID'),
            'course_id' => $this->string(50)->notNull()->defaultValue('')->comment('课程ID'),
            'course_catalog_id' => $this->string(50)->notNull()->defaultValue('0')->comment('节ID'),

            'title' => $this->string()->notNull()->defaultValue('')->comment('素材名称'),
            'file_id' => $this->string(50)->notNull()->defaultValue('')->comment('素材ID，-1为习题'),
            'ordernum' => $this->integer()->notNull()->defaultValue(0)->comment('排序号'),
            'topicpercent' => $this->smallInteger()->notNull()->defaultValue(100)->comment('出题率 从所有以前是中出几道题'),
            'rightpercent' => $this->smallInteger()->notNull()->defaultValue(100)->comment('正确率 答对百分比就可以通过'),
            'showright' => $this->smallInteger()->notNull()->defaultValue(0)->comment('显示答案 0：不显示正确  1：显示正确  2：显示正确和答案'),

            'status' => $this->smallInteger()->notNull()->defaultValue(10)->comment('状态'),
            'created_at' => $this->integer()->notNull()->defaultValue(0)->comment('创建时间'),
            'updated_at' => $this->integer()->notNull()->defaultValue(0)->comment('更新时间'),
        ], $tableOptions);

        $this->addCommentOnTable('{{%course_content}}','课程素材表');

        $this->addPrimaryKey('course_content_id','{{%course_content}}','id');
    }

    /**
     * @inheritdoc
     */
    public function safeDown()
    {
        $this->dropTable('{{%course_content}}');
    }

    /*
    // Use up()/down() to run migration code without a transaction.
    public function up()
    {

    }

    public function down()
    {
        echo "m171206_062801_createTableContent cannot be reverted.\n";

        return false;
    }
    */
}
